package com.gusto.engine.clusterant.graph;

import java.util.List;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import com.gusto.engine.clusterant.algorithms.kmeansclustering.ClusterObject;
import com.gusto.engine.clusterant.model.Point;

public class ClusterPlanGraph {
	
	public static JFreeChart getClusterPlanScatterPlotGraph(List<ClusterObject> clusters/*, int PARAM_ROWS, int PARAM_COLS*/) {
		/*
		XYSeries series1 = new XYSeries("Test Data");
		for (com.gusto.engine.clusterant.model.Point p : plan.getPoints()) {
			//series1.add(p.getCol(), PARAM_ROWS - p.getRow());
			XYDataItem xy = new XYDataItem(p.getCol(), PARAM_ROWS - p.getRow());
			series1.add(xy);
		}
		*/
		XYSeriesCollection sc = new XYSeriesCollection();
		XYSeries centers = new XYSeries("Centers");
		for (ClusterObject c : clusters) {
			XYSeries s = new XYSeries("Test Data");
			if ((c.getCol()>0) && (c.getCol()>0)) {
				//centers.add(c.getCol() + 1.2, PARAM_ROWS + 1.2 - c.getRow());
				centers.add(c.getCol() + 1.2, c.getRow() + 1.2);
			}
			for (Point p : c.getComponents()) {
				s.add(p.getCol() + 1, p.getRow() + 1);
			}
			sc.addSeries(s);
		}
		sc.addSeries(centers);
		
		JFreeChart chart = ScatterPlotGraph.getPoints(sc);
		return chart;
	}
	
	public static void displayAsSwing(JFreeChart jfreeChart) {
		ChartFrame frame = new ChartFrame("Clustering", jfreeChart);
    	frame.pack();
    	frame.setVisible(true);
	}
	
}
